/*
 * Copyright (c) 2014 pkzd/1.0, 颜文泽(robin)
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     1 Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     2 Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include	<asm.h>
#include	<syscall.h>

int
syscall(int num, int p1, int p2, int p3)
{
#if 0
        asm volatile("movl %%ebp, %0" : "=a"(up->p_lesp));
#endif
        switch(num){
	case FORK:
		return fork();	
	case EXECVE:
		return execve(p1, p2, p3); 
	case EXIT:
		return exit(p1);
	case WAIT:
		return wait(p1);
	case GETPID:
		return getpid();
	case GETPPID:
		return getppid();
	case GETUID:
		return getuid();
	case GETEUID:
		return geteuid();	
	case GETGID:
		return getgid();
	case GETEGID:
		return getegid();
	case SETPGID:
		return setpgid();
	case CREAT:
		return creat(p1, p2);
	case OPEN:
		return open(p1, p2, p3);
	case CLOSE:
		return close(p1);
	case DUP:
		return dup(p1);
	case READ:
		return read(p1, p2, p3);
	case WRITE:
		return write(p1, p2, p3);
	case LSEEK:
		return lseek(p1, p2, p3);
	case MKNOD:
		return mknod(p1, p2, p3);
	case ACCESS:
		return access(p1, p2);
	case LINK:
		return link(p1, p2);
	case UNLINK:
		return unlink(p1);
	case MKDIR:
		return mkdir(p1, p2);
	case RMDIR:
		return rmdir(p1);
	case CHDIR:
		return chdir(p1);
	case TIME:
		return time(p1);
	case STAT:
		return stat(p1, p2);
	case FSTAT:
		return fstat(p1, p2);
	case BRK:
		return brk(p1);
        default:
		up->p_error = ENOSYS;
                return -1;
        }
}
